home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_075 / copy / setdate.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  153 lines

  1. #include "exec/types.h"
  2. #include "exec/ports.h"
  3. #include "exec/io.h"
  4. #include "exec/memory.h"
  5. #include "libraries/dos.h"
  6. #include "libraries/dosextens.h"
  7. #include <stdio.h>
  8. #define AZTEC 1
  9. #ifdef AZTEC
  10. #include "functions.h"         /* aztec C include */
  11. #endif
  12.  
  13. #define ACTION_SETDATE_MODE 34L  /* The packet type we will be playing with */
  14. #define DOSTRUE         -1L  /* AmigaDos TRUE */
  15. #define MAXARGS              7L  /* limit in packet structure (dosextens.h) */
  16. #define NARGS             4L  /* Number of args for setdate */
  17.  
  18. /*---------------------------------------------------------------------*/
  19. /*  sendpkt: generalized send a dos packet.                   */
  20. /*---------------------------------------------------------------------*/
  21.  
  22. static long sendpkt(pid,action,args,nargs)
  23.  
  24. struct MsgPort *pid;    /* process indentifier ... (handlers message port ) */
  25. long  action,           /* number of arguments in list */
  26.       nargs;           /* number of arguments in list  */
  27. ULONG args[];          /* a pointer to a argument list */
  28. {
  29.  
  30.    struct MsgPort        *replyport;
  31.    struct StandardPacket *packet;
  32.  
  33.    long   count, res1; 
  34.    ULONG  *pargs;
  35.  
  36.    if(nargs > MAXARGS) return NULL; 
  37.  
  38.    replyport = (struct MsgPort *) CreatePort(NULL,NULL); /* make reply port */
  39.    if(!replyport) return NULL;
  40.  
  41.    packet = (struct StandardPacket *) 
  42.       AllocMem((long)sizeof(struct StandardPacket),MEMF_PUBLIC | MEMF_CLEAR);
  43.    if(!packet) 
  44.      {
  45.        FreeMem((void *)packet,(long)sizeof(struct StandardPacket));
  46.        return(NULL);
  47.      }
  48.  
  49.    packet->sp_Msg.mn_Node.ln_Name = (char *) &(packet->sp_Pkt); /* link packet- */
  50.    packet->sp_Pkt.dp_Link         = &(packet->sp_Msg);  /* to message    */
  51.    packet->sp_Pkt.dp_Port         = replyport;         /* set-up reply port */
  52.    packet->sp_Pkt.dp_Type         = action;           /* what to do... */
  53.  
  54.    /* move all the arguments to the packet */
  55.    pargs = (ULONG *)&(packet->sp_Pkt.dp_Arg1);   /* address of first argument */
  56.    for(count=NULL;count < nargs && count < MAXARGS; ++count) 
  57.      pargs[count]=args[count];
  58.  
  59.    PutMsg(pid,packet); /* send packet */
  60.    (void)WaitPort(replyport); /* wait for packet to come back */
  61.    (void)GetMsg(replyport);   /* pull message */
  62.  
  63.    res1 = packet->sp_Pkt.dp_Res1; /* get result */
  64.  
  65.    /* all done clean up */
  66.    FreeMem((void *)packet,(long)sizeof(*packet)); 
  67.    DeletePort(replyport); 
  68.  
  69.    return(res1); 
  70.  
  71. }
  72.  
  73. /*---------------------------------------------------------------------*/
  74. /*  setDate: datestamp the given file with the given date.           */
  75. /*---------------------------------------------------------------------*/
  76.  
  77. BOOL setDate( name, date )
  78. char          *name;
  79. struct DateStamp *date;
  80. {
  81.    struct MsgPort *task;            /* for process id handler */
  82.    ULONG arg[4];                    /* array of arguments     */
  83.    char *bstr, strcpy();            /* of file to be set      */
  84.    long rc;
  85.    char *strchr();
  86.    int strlen();
  87.  
  88.    rc = 0;
  89.  
  90.    if ( !(bstr = (char *)AllocMem(68L, (long)(MEMF_PUBLIC)))) goto exit2;
  91.    if ( !(task = (struct MsgPort *)DeviceProc( name )))       goto exit1;
  92.  
  93.    /* Dos Packet needs the filename in Bstring format */
  94.  
  95.    (void)strcpy( bstr+1, name );
  96.    *bstr = strlen( name );
  97.  
  98.    arg[0] = (ULONG)NULL;
  99.    arg[1] = (ULONG)IoErr(); /* lock on parent director set by DeviceProc() */
  100.    arg[2] = (ULONG) bstr >> 2;
  101.    arg[3] = (ULONG) date;
  102.    rc = sendpkt( task, ACTION_SETDATE_MODE, arg, 4L );
  103.  
  104. exit1: if ( bstr ) FreeMem( (void *)bstr, 68L );
  105. exit2: if ( rc == DOSTRUE )
  106.           return TRUE;
  107.        else
  108.           return FALSE;
  109. }
  110.  
  111. /*---------------------------------------------------------------------*/
  112. /*  getDate: get the datestamp the given file.                   */
  113. /*---------------------------------------------------------------------*/
  114.  
  115. BOOL getDate(name, date )
  116. char *name;
  117. register struct DateStamp *date;
  118. {
  119.  
  120.    struct FileInfoBlock *Fib;
  121.    ULONG        FLock;
  122.    int            result;
  123.    register struct DateStamp    *d;
  124.  
  125.    if ( (FLock = (ULONG) Lock(name, (long)(ACCESS_READ) )) == NULL)
  126.       return FALSE;
  127.  
  128.    Fib = (struct FileInfoBlock * )
  129.     AllocMem( (long)sizeof(struct FileInfoBlock), (long)(MEMF_CHIP));
  130.  
  131.    if (Fib == NULL )
  132.      result = FALSE;
  133.    else
  134.      {
  135.     if ( !Examine( FLock, Fib ))
  136.        result = FALSE;
  137.     else if ( Fib->fib_DirEntryType > 0 )
  138.        result = FALSE;  /* It's a directory */
  139.         else
  140.        {
  141.         d = &Fib->fib_Date;
  142.         date->ds_Days   = d->ds_Days;
  143.         date->ds_Minute = d->ds_Minute;
  144.         date->ds_Tick   = d->ds_Tick;        
  145.         result = TRUE;
  146.        }
  147.     FreeMem( (void *)Fib, (long)sizeof(struct FileInfoBlock) );
  148.      }
  149.  
  150.    UnLock( FLock );
  151.    return result;
  152. }
  153.